// index.js
// 获取应用实例
const app = getApp()
const api = require('../../api/api')
Page({
  data: {
    title: '',
    info: '',
    goodsList: [],
    id: ''
  },
  onLoad() {
    this.page = 1;
    // this.getGoods()

  },
  searchFocus() {
    wx.navigateTo({
      url: '../../pages/searchDetails/searchDetails',
    })
  },
  getGoods(bottom) {

    wx.request({
      url: api.getGoods.url,
      method: api.getGoods.method,
      data: {
        pageNum: this.page,
        count: 10
      },
      success: res => {
        console.log(res)
        var info = res.data.data
        if (info.length != 0) {
          for (let index = 0; index < info.length; index++) {
            const element = info[index]["img"];
            info[index]["img"] = info[index]["img"].split('|')
          }
          //分页判断
          if (bottom) {
            this.setData({
              goodsList:this.data.goodsList.concat(info)
            })
          }else{
            this.setData({
              goodsList:info
            })
          }
        }
      }
    })
  },
  onShow() {
    this.getGoods(false)
  },
  //分页处理
  onReachBottom() {
    this.page += 1
    this.getGoods(true)
  },
})